package com.example.chenhaosblog.service.impl;


import com.example.chenhaosblog.bean.User;
import com.example.chenhaosblog.mapper.DaoSupport;
import com.example.chenhaosblog.mapper.UserDao;
import com.example.chenhaosblog.service.IUserService;
import com.example.chenhaosblog.utils.Page;
import com.example.chenhaosblog.utils.PageData;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class IUserServiceImpl  implements IUserService {
    @Autowired
    private UserDao userDao;

    @Resource(name = "daoSupport")
    private DaoSupport dao;

    @Override
    public List<User> findAllUser() {
        return userDao.findAllUser();
    }

    @Override
    public void createUser(User user) throws Exception {
        //userDao.createUser(user);
        dao.save("UserMapper.createUser", user);

    }

    @Override
    public void createUser2(PageData pageData) throws Exception {
        dao.save("UserMapper.createUser2",pageData);
    }

    @Override
    public List<PageData> findAll(PageData pageData) throws Exception {
        return (List<PageData>) dao.findForList("UserMapper.findAll", pageData);
    }

    @Override
    public String getPasswordByUsername(String username) {
        return null;
    }

    @Override
    public User findByUsername(PageData pageData) throws Exception {
        return (User)dao.findForObject("UserMapper.findByUsername", pageData);
    }

    @Override
    public void add(PageData pageData) throws Exception {
        dao.save("UserMapper.add",pageData);
    }

    @Override
    public PageData findByUser(PageData pageData) throws Exception {
        return (PageData)dao.findForObject("UserMapper.findByUser", pageData);
    }

    @Override
    public List<PageData> list(Page page) throws Exception {
        return (List<PageData>) dao.findForList("UserMapper.datalistPage", page);
    }

    @Override
    public List<PageData> queryArticle(PageData pageData) throws Exception {
        return (List<PageData>) dao.findForList("UserMapper.queryArticle", pageData);
    }

}
